package com.example.lib_common.init

import android.content.Context
import androidx.startup.Initializer
import com.example.lib_common.BuildConfig
import com.example.lib_common.logger.MyCsvFormatStrategy
import com.example.lib_common.logger.MyPrettyFormatStrategy
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.DiskLogAdapter
import com.orhanobut.logger.FormatStrategy
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy
import java.io.File
import kotlin.jvm.java


class LoggerInit : Initializer<Int> {
    override fun create(context: Context): Int {

        val debugStrategy: FormatStrategy = MyPrettyFormatStrategy.newBuilder()
//            .showThreadInfo(false) // (Optional) Whether to show thread info or not. Default true
            .methodCount(0) // (Optional) How many method line to show. Default 2
//            .methodOffset(7) // (Optional) Hides internal method calls up to offset. Default 5
//            .logStrategy(customLog) // (Optional) Changes the log strategy to print out. Default LogCat
            .tag("") // (Optional) Global tag for every log. Default PRETTY_LOGGER
            .build()
        Logger.addLogAdapter(AndroidLogAdapter(debugStrategy))
        if (BuildConfig.DEBUG) {
            val savePath = File(context.externalCacheDir, "Logger").absolutePath
            val diskStrategy: FormatStrategy =
                MyCsvFormatStrategy.newBuilder().tag("hjw_debug").savePath(savePath).build()
            Logger.addLogAdapter(DiskLogAdapter(diskStrategy))
        }
        return 0
    }

    override fun dependencies(): List<Class<out Initializer<*>?>?> {
        return listOf(CrashInit::class.java, MMKVInit::class.java)
    }
}